let that
// 串口监听
export default {
	data() {
		return {
			current:0,
			lists: [],
			currPage:1,
			pageSize:10,
			orderStatus:null,
			loadingType:'more',
			total:0,
		}
	},
	computed: {},
	onShow() {
		that.currPage = 1
		that.getMyOrderList();
	},
	created() {
		that = this
	},
	onReady() {},
	onLoad(options) {
		that = this
		// that.getMyOrderList();
	},
	onReachBottom() {
		this.loadMoreData();
	},
	methods: {
		changeMenu(e) {
			that.current = e
			that.currPage = 1
			switch(e){
				case 0:
					that.orderStatus = null
					break;
				case 1:
					that.orderStatus = '0,5,12'
					break;
				case 2:
					that.orderStatus = '2,3,4,5,6,7,12'
					break;
				case 3:
					that.orderStatus = '8,9'
					break;
				case 4:
					that.orderStatus = '1,6'
					break;
				case 5:
					that.orderStatus = '11'
					break;
			}
			that.getMyOrderList();
		},
	
		gotoInfo(item) {
			uni.setStorageSync("userInfoAudit", item)
			uni.navigateTo({
				url: '/pages/audit/details/index?id=' + item.id
			})
		},
		getMyOrderList(){
			uni.request({
				url: '/api/h5/getMyOrder',
				method: "POST",
				header: {},
				data: {
					"currPage":that.currPage,
					"pageSize":that.pageSize,
					"orderStatus":that.orderStatus,
					"userId": uni.getStorageSync('userId')
				},
				success: (res) => {
					if(that.currPage == 1){
						that.lists = []
					}
					that.lists = that.lists.concat( res.data.data.list)
					that.total = res.data.data.count
					if(that.currPage*that.pageSize >= that.total){
						that.loadingType = 'noMore'
					}else{
						that.loadingType = 'more'
					}
				},
				fail: (err) => {
					console.error(err);
				}
			});
		},
		loadMoreData(){
			if(that.total > that.currPage * that.pageSize){
				that.loadingType = 'loading'
				that.currPage++
				// TODO 分页查询
				that.getMyOrderList();
			}else{
				return;
			}
		},
		
		cancelOrder(item) {
			let that = this
			uni.showModal({
				title: "温馨提示",
				content: "您确认要取消申请吗?",
				confirmText: "确定",
				// confirmColor: '#FF802D',
				success: function(res) {
					if (res.confirm) {
						// 用户点击确定操作
						uni.request({
							url: '/api/h5/deviceCancelApply',
							method: "POST",
							header: {},
							data: {
								"orderId": item.id
							},
							success: (res) => {
								that.currPage = 1
								that.getMyOrderList()
							},
							fail: (err) => {
								console.error(err);
							}
						});
					}
				}
			})
		}
	}
}